<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : !disabled ? '修改' : '查看'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="姓名" prop="persName">
        <el-input v-model="dataForm.persName" :disabled="disabled" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <!--<el-input v-model="dataForm.sex" :disabled="disabled" placeholder=""></el-input>-->
        <el-dict code="SEX" v-model="dataForm.sex" :disabled="disabled"></el-dict>
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input v-model="dataForm.age" :disabled="disabled" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="街道" prop="street">
        <el-input v-model="dataForm.street" :disabled="disabled" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="社区" prop="community">
        <el-input v-model="dataForm.community" :disabled="disabled" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="详细地址" prop="address">
        <el-input v-model="dataForm.address" :disabled="disabled" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="证件号" prop="idNumber">
        <el-input v-model="dataForm.idNumber" :disabled="disabled" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="联系方式" prop="contact">
        <el-input v-model="dataForm.contact" :disabled="disabled" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="医院诊断结论" prop="diagnosis">
        <el-input v-model="dataForm.diagnosis" :disabled="disabled" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="诊断医院名称" prop="hospital">
        <el-input v-model="dataForm.hospital" :disabled="disabled" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="病例分类" prop="illState">
        <el-input v-model="dataForm.illState" :disabled="disabled" placeholder="病例分类"></el-input>
        <!--<el-dict code="ILL_STATE" v-model="dataForm.illState" :disabled="disabled"></el-dict>-->
      </el-form-item>
      <el-form-item label="是否做了核酸检测检测" prop="rna">
        <el-input v-model="dataForm.rna" :disabled="disabled" placeholder="是否做了核酸检测检测"></el-input>
        <!--<el-dict code="DO_RNA" v-model="dataForm.rna" :disabled="disabled"></el-dict>-->
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="dataForm.remark" :disabled="disabled" placeholder=""></el-input>
      </el-form-item>
      <!--<el-form-item label="" prop="createUserId">-->
        <!--<el-input v-model="dataForm.createUserId" :disabled="disabled" placeholder=""></el-input>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="" prop="createUserOrgNo">-->
        <!--<el-input v-model="dataForm.createUserOrgNo" :disabled="disabled" placeholder=""></el-input>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="" prop="createTime">-->
        <!--<el-input v-model="dataForm.createTime" :disabled="disabled" placeholder=""></el-input>-->
      <!--</el-form-item>-->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button v-if="!disabled" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        disabled: false,
        visible: false,
        dataForm: {
          persId: 0,
          persName: '',
          sex: '',
          age: '',
          street: '',
          community: '',
          address: '',
          idNumber: '',
          contact: '',
          diagnosis: '',
          hospital: '',
          illState: '',
          rna: '',
          remark: '',
          createUserId: '',
          createUserOrgNo: '',
          createTime: ''},
        dataRule: {
          name: [
            {required: true, message: '名称不能为空', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      init (id, disabled) {
        this.disabled = disabled
        this.dataForm.id = id || ''
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: `/ncp/personinfo/info/${this.dataForm.id}`,
              method: 'get'
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm = data.personinfo
                this.dataForm.id = id
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm']
          .validate((valid) => {
            if (valid) {
              this.$http({
                url: `/ncp/personinfo/${!this.dataForm.id ? 'save' : 'update'}`,
                method: 'post',
                data: this.dataForm
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500
                  })
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            }
          })
      }
    }
  }
</script>
